<?php
/**
 * 题库讲评
 */
namespace Admin\Frontend\Controllers;

use Admin\Models\statsexplain\TreeHomeworkList;
use Helpers\Assets;
use Helpers\Main;
use Helpers\UserPower;
use Helpers\Template;
use Helpers\Cache;
use Phalcon\Di;
use Phalcon\Db\Column;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Admin\Models\statsexplain\ExplainStats;


class StatsexplainController extends ControllerBase
{
    const Key     = 'xhtest';       //文件服务器key
    const Service = 'statsExplainDB';
    const  OldService = 'oldCenterDB';
    const  CoursePlay = 'coursePlay';
    /**
     * 初始化时连接数据库
     *
     * create by zsc 20170406
     */
    protected function initialize()
    {
        error_reporting(E_ERROR);
        self::setDBService();
        self::setOldDBService();
    }


    public static function setOldDBService($dbname=null)
    {
        $dbService = Main::getConfigByName(self::Service);
        $oldCenterDB  = explode("|",$dbService['oldCenterDB']);
        $oldCenterDB[3] = $dbname?$dbname:$oldCenterDB[3];
        $dbService = [
            'host'     => $oldCenterDB[0],
            'username' => $oldCenterDB[1],
            'password' => $oldCenterDB[2],
            'dbname'   => $oldCenterDB[3],
            'charset'  => $oldCenterDB[4],
        ];
        Di::getDefault()->setShared(self::OldService, function() use ($dbService){
            return new Mysql($dbService);
        });
    }

    /**
     * 连接扬老的数据中心数据库
     *
     * create by zsc 20170406
     */
    public static function setDBService()
    {
        $dbService = Main::getConfigByName(self::Service);
        $explainDBArr  = explode("|",$dbService['readDB']);
        $explainDB = [
            'host'     => $explainDBArr[0],
            'username' => $explainDBArr[1],
            'password' => $explainDBArr[2],
            'dbname'   => $explainDBArr[3],
            'charset'  => $explainDBArr[4],
        ];
        Di::getDefault()->setShared(self::Service, function() use ($explainDB){
            return new Mysql($explainDB);
        });
    }


    /**
     * #方法说明:查看题库使用情况
     * # create by zsc
     */
    public function qBankListAction()
    {
        Assets::easyUI('js/statsexplain/getqBankList.js');
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));
        $this->view->setVar('NavUl', '<ul class="breadcrumb"><li><i class="fa fa-home fa-lg"></i> 主页</li><li>统计查询</li><li>题库讲评</li><li>题库查看</li></ul>');
        $listButtonArr = $listSearchArr = array();
        $listSearchArr[] = ['type'=>'text', 'id'=>'list_search', 'name'=>'list_search', 'label'=>'搜索： '];
        $this->view->setVars(array(
            'List'          => Template::createList('List', 'Explain_qBank', [
                'searchToolbar' => Template::createSearchToolBar($listSearchArr, true),
                'buttonToolbar' => Template::createButtonToolBar($listButtonArr),
            ]),
        ));
        $this->view->pick('statsexplain/qBankList');
    }

    /**
     * #方法说明：获取题库使用列表
     * # Created by zsc
     */
    public function getqBankListAction(){
       $result =  $this->getDI()->get(self::OldService);
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));
        $this->view->disable();
		$search =  $this->request->getPost('search');
        $keyword = trim($search['vague']);
        if($keyword){
			$conditions = "1 AND (tr_name like '%{$keyword}%')";
            $parameters = [
                'columns'    => ['tr_id'],
                'conditions'    =>  $conditions,
                'bind'          => []
            ];
            $oExplainUserList = TreeHomeworkList::find($parameters)->toArray();
            $iSysTrIdArr = array_column($oExplainUserList, 'tr_id');//找粗所有的用户
        }
        $parameters = [
            'columns'    => ['count(iESId) as iESNum', 'iSysTrId','max(tSyncTime) as tSyncTime'],
            'order'      => 'tSyncTime DESC',
            'HAVING'     => 'tSyncTime = max(tSyncTime)',
            'conditions' => $iSysTrIdArr?'1 AND iSysTrId IN('.implode(',',$iSysTrIdArr).')':'',
            'group'      => 'iSysTrId'
        ];
        $data = Main::runModelPaginator('\\Admin\\Models\\statsexplain\\ExplainStats', $parameters, true);
        $oSchoolNumData =  $oSysTrNameData = [];
        if(count($data['rows'])){
            $sysTrIds = array_column($data['rows'], 'iSysTrId');
            $parameters = [
                'columns'    => [ 'iSysTrId','iSchoolId'],
                'order'      => 'iSysTrId ASC',
              //  'group'      => 'iSchoolId',
                'conditions'    => 'iSysTrId IN ({idArr:array})',
                'bind'          => array(
                    'idArr'         => $sysTrIds
                )
            ];

            $oSchoolArr = ExplainStats::find($parameters)->toArray();
            if($oSchoolArr)foreach ($oSchoolArr as $value)$oSchoolNumData[$value['iSysTrId']][$value['iSchoolId']] += 1;
            $oSysTrNameData = TreeHomeworkList::getTrNameById($sysTrIds);
            $oStaTrArr =array();
            if($sysTrIds)foreach ( $sysTrIds as $k => $value){
                $timesArr = $this->getDI()->get(self::OldService)->query("select sum(li_times) as times from xh_product_exam{$value}.list_courseware where 1 ")->fetch();
                $oStaTrArr[$value]['sDuration'] = $timesArr['times']?$timesArr['times']:0;
                $oStaTrArr[$value]['iTopicNum'] = $this->getDI()->get(self::OldService)->query("select ho_id as num from xh_product_exam{$value}.homework_list_base where ho_status = 1")->numRows();
                $oStaTrArr[$value]['iCourseWareNum'] = $this->getDI()->get(self::OldService)->query("select li_id as num from xh_product_exam{$value}.list_courseware where 1")->numRows();
                $oStaTrArr[$value]['iCourseWareTopicNum'] = $this->getDI()->get(self::OldService)->query("select li_id as num from xh_product_exam{$value}.list_courseware where 1 GROUP  BY  li_ho_id")->numRows();
            }
            foreach ($data['rows'] as $key => $value) {
                $data['rows'][$key]['iSchoolNum'] = count($oSchoolNumData[$value['iSysTrId']]);
                $data['rows'][$key]['iESNum'] = array_sum($oSchoolNumData[$value['iSysTrId']]);
                $data['rows'][$key]['sSysTrName'] = $oSysTrNameData[$value['iSysTrId']]."({$value['iSysTrId']})";
                $data['rows'][$key]['sDuration'] = ExplainStats::transform($oStaTrArr[$value['iSysTrId']]['sDuration']);
                $data['rows'][$key]['iTopicNum'] = $oStaTrArr[$value['iSysTrId']]['iTopicNum'];
                $data['rows'][$key]['iCourseWareNum'] = $oStaTrArr[$value['iSysTrId']]['iCourseWareNum'];
                $data['rows'][$key]['iCourseWareTopicNum'] = $oStaTrArr[$value['iSysTrId']]['iCourseWareTopicNum'];
            }
        }

        $this->response->setJsonContent($data)->send();
    }


    public function qBankInfoAction(){
        Assets::easyUI('js/statsexplain/getqBankInfo.js');
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain_Exam') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));


        $this->view->setVar('NavUl', '<ul class="breadcrumb"><li><i class="fa fa-home fa-lg"></i> 主页</li><li>统计查询</li><li>题库讲评</li><li>题库详情</li></ul>');
        $listButtonArr = array();

        $listSearchArr[] = ['type'=>'text', 'id'=>'list_search', 'name'=>'list_search', 'label'=>'搜索： '];
        $this->view->setVar('List', Template::createList('List', 'Explain_qBankInfo', [
            'searchToolbar' => Template::createSearchToolBar($listSearchArr, true),
            'buttonToolbar' => Template::createButtonToolBar($listButtonArr)
        ]));
        $this->view->pick('statsexplain/qBankInfo');
    }

    /**
     * #方法说明：题库老师录制数量和讲评使用学校数量
     * # Created by zsc
     */

    public function getqBankInfoAction()
    {
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain_Exam') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));
        $this->view->disable();
        $iSysTrId =  $this->request->getPost('iSysTrId', 'int');
        $search =  $this->request->getPost('search');
        $keyword = trim($search['vague']);
        $parameters = [
            'columns'    => [ 'iUserId','sUserName'],
            'order'      => 'iUserId ASC',
            'conditions'    => "sUserName like '%{$keyword}%'  OR iUserId = '{$keyword}'",
            'bind'          => array(
                'keyword'        => trim($search['vague'])
            )
        ];
        $bind = [];
        $conditions = '1 ';
        $oUserList = \Admin\Models\user\XhsysUser::find($parameters)->toArray();
        if($search['vague']){
            $conditions .= ' AND iCreateUserId in ({iCreateUserId:array}) ';
            $bind['iCreateUserId'] = $oUserList?array_column($oUserList,'iUserId'):[0];
        }
        $iSysTrId = $iSysTrId?$iSysTrId:$this->request->get('iSysTrId', 'int');
        if($iSysTrId){
            $conditions .= ' AND iSysTrId = {iSysTrId} ';
            $bind['iSysTrId'] = $iSysTrId;
        }
        $parameters = [
            'columns'    => ['count(iESId) as iESNum', 'iCreateUserId' ,'max(tSyncTime) as tSyncTime'],
            'group'      => 'iCreateUserId',
            'order'      => 'tSyncTime DESC',
            'HAVING'     => 'tSyncTime = max(tSyncTime)',
            'conditions'    =>  $conditions,
            'bind'          => $bind
        ];


        $data = Main::runModelPaginator('\\Admin\\Models\\statsexplain\\ExplainStats', $parameters, true);
        $oSchoolNumData =  $oSysTrNameData = $oCreateUserArr =[];
        if(count($data['rows'])){
            $userIdArr = array_column($data['rows'], 'iCreateUserId');//找出使用的学校
            /***老师录制详细**/
            if($userIdArr){
                $teracherWhere = "ANd li_us_id in(".implode(',',$userIdArr).")";
                $teracherCourseWareList = $this->getDI()->get(self::OldService)->query("select count(li_id) as num,sum(li_times) as li_times,li_us_id from xh_product_exam{$iSysTrId}.list_courseware where 1 {$teracherWhere} group by li_us_id")->fetchAll();
                $oCreateTeacherData = ExplainStats::find(
                    [
                        'columns'    => [ 'count(iESId) as iKjlzSum,sum(iDuration) as iKjlzDuration','iCreateUserId'],
                        'order'      => 'tCreateTime ASC',
                        'group'      => 'iCreateUserId,iSchoolId',
                       // 'conditions'    => 'iSchoolId = 4160 AND iSysTrId = {iSysTrId} AND iCreateUserId in( {userIdArr:array} )',
                        'conditions'    => 'iStatus  = 1 AND iSysTrId = {iSysTrId} AND iCreateUserId in( {userIdArr:array} )',
                        'bind'          => ['userIdArr'=> $userIdArr,'iSysTrId'=> $iSysTrId],
                    ]
                )->toArray();
                if($teracherCourseWareList)foreach ($teracherCourseWareList as $key => $value){
                    $teracherCourseWareData[$value['li_us_id']] = array('iESNum' => $value['num'],'sDuration'=> $value['li_times']);
                }
                if($oCreateTeacherData)foreach($oCreateTeacherData as $key => $value){
                    $teracherCourseWareData[$value['iCreateUserId']]['iKjlzSum'] = $value['iKjlzSum'];
                    $teracherCourseWareData[$value['iCreateUserId']]['iKjlzDuration'] = $value['iKjlzDuration'];
                }

            }
            /***老师录制详细**/
            /***学校使用数量***/
            $parameters = [
                'columns'    => [ 'count(iSchoolId) as iSchoolNum','iCreateUserId'],
                'order'      => 'tCreateTime ASC',
                'group'      => 'iSchoolId,iCreateUserId',
                'conditions'    => $iSysTrId?'iSysTrId = {iSysTrId} AND iCreateUserId in( {userIdArr:array} )':'iCreateUserId in( {userIdArr:array} )',
                'bind'          => $iSysTrId?['iSysTrId'=> $iSysTrId, 'userIdArr'=> $userIdArr]:[ 'userIdArr'=> $userIdArr?$userIdArr:[0]],
            ];
            $oCreateUserData = ExplainStats::find($parameters)->toArray();
            if($oCreateUserData)foreach ($oCreateUserData as $key => $value)$oCreateUserArr[$value['iCreateUserId']] +=1;
            /***学校使用数量***/
            $userInfoArr = \Admin\Models\user\XhsysUser::getUserNameById($userIdArr);
            foreach ($data['rows'] as $key => $value) {
                $data['rows'][$key]['iESNum'] = $teracherCourseWareData[$value['iCreateUserId']]['iESNum']?$teracherCourseWareData[$value['iCreateUserId']]['iESNum']:0;
                $data['rows'][$key]['iKjlzSum'] =  $teracherCourseWareData[$value['iCreateUserId']]['iKjlzSum']?$teracherCourseWareData[$value['iCreateUserId']]['iKjlzSum']:0;
                $data['rows'][$key]['iKjlzDuration'] =  ExplainStats::transform($teracherCourseWareData[$value['iCreateUserId']]['iKjlzDuration']?$teracherCourseWareData[$value['iCreateUserId']]['iKjlzDuration']:0);
                $data['rows'][$key]['iSchoolNum'] = $oCreateUserArr[$value['iCreateUserId']];
                $data['rows'][$key]['sUserName'] = $userInfoArr[$value['iCreateUserId']];
                $data['rows'][$key]['sDuration'] = ExplainStats::transform($teracherCourseWareData[$value['iCreateUserId']]['sDuration']);
            }
        }
        $this->response->setJsonContent($data)->send();
    }


    public function teacherRecListAction(){
        Assets::easyUI('js/statsexplain/teacherRecList.js');
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain_List') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));

        $this->view->setVar('NavUl', '<ul class="breadcrumb"><li><i class="fa fa-home fa-lg"></i> 主页</li><li>统计查询</li><li>题库讲评</li><li>录制列表</li></ul>');
        $listButtonArr = array();
        //$listSearchArr[] = array('type'=>'select', 'id'=>'List_Search_Status', 'data'=>array('0'=>'按照老师姓名','1'=>'按照题库名称'));
        $listSearchArr[] = ['type'=>'text', 'id'=>'list_search', 'name'=>'list_search', 'label'=>'搜索： '];
        $this->view->setVar('List', Template::createList('List', 'ExplainRec_List', [
            'searchToolbar' => Template::createSearchToolBar($listSearchArr, true),
            'buttonToolbar' => Template::createButtonToolBar($listButtonArr)
        ]));
        $this->view->pick('statsexplain/teacherRecList');
    }



    /**
     * #方法说明：题库老师录制数量和讲评使用学校数量
     * # Created by zsc
     */

    public function getTeacherRecListAction()
    {
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain_List') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));
        $this->view->disable();
        $search =  $this->request->getPost('search');
        $keyword = trim($search['vague']);
        if($keyword){
            $parameters = [
                'columns'    => ['iCreateUserId'],
                'order'      => 'tCreateTime ASC',
                'group'      => 'iCreateUserId',
                'conditions'    =>  [],
                'bind'          => []
            ];
            $oExplainUserList = \Admin\Models\statsexplain\ExplainStats::find($parameters)->toArray();
            $userIdArr = array_column($oExplainUserList, 'iCreateUserId');//找出所有的用户
            $conditions = 1;
            $conditions .= ' AND iUserId in ({iUserId:array})';
            $conditions .= "AND (sUserName like '%{$keyword}%'  OR iUserId = '{$keyword}')";
            $parameters = [
                'columns'    => [ 'iUserId','sUserName'],
                'order'      => 'iUserId ASC',
                'conditions'    => $conditions,
                'bind'          => array(
                    'iUserId'        => $userIdArr
                )
            ];
            $oUserList = \Admin\Models\user\XhsysUser::find($parameters)->toArray();
        }

        $bind = [];
        $conditions = '1 AND iStatus  = 1 ';
        if($oUserList){
                $userIdArr = array_column($oUserList, 'iUserId');
                $conditions .= 'AND iCreateUserId IN( {userIdArr:array} )';
                $bind['userIdArr'] = $userIdArr;
        }elseif($keyword && !$oUserList){
                $treeConditions = "1 AND (tr_name like '%{$keyword}%')";
                $parameters = [
                    'columns'    => ['tr_id'],
                    'conditions'    =>  $treeConditions,
                    'bind'          => []
                ];
                $oExplainUserList = TreeHomeworkList::find($parameters)->toArray();
                $iSysTrIdArr = array_column($oExplainUserList, 'tr_id');//找粗所有的用户
            if($iSysTrIdArr){
                $conditions .= 'AND iSysTrId IN( {iSysTrIdArr:array} )';
                $bind['iSysTrIdArr'] = $iSysTrIdArr;
            }else{
                $this->response->setJsonContent(array())->send();
            }
        }
        //$conditions.=' AND iSchoolId = 4160';
        $parameters = [
            'columns'    => [ 'count(iESId) as iKjlzSum,sum(iDuration) as iKjlzDuration','iCreateUserId','iSysTrId' ,'max(tSyncTime) as tSyncTime'],
            'order'      => 'tSyncTime DESC',
            'HAVING'     => 'tSyncTime = max(tSyncTime)',
            'group'      => 'iCreateUserId,iSysTrId',
            'conditions'    =>  $conditions,
            'bind'          => $bind
        ];
        $data = Main::runModelPaginator('\\Admin\\Models\\statsexplain\\ExplainStats', $parameters, true);
        if($oUserList && count($data['rows'])){
            $oUserInfo = array_column($oUserList,'sUserName','iUserId');
        }elseif(count($data['rows'])){
            $oUserInfo = \Admin\Models\user\XhsysUser::getUserNameById(array_column($data['rows'],'iCreateUserId'));
        }
       // print_r($data['rows']);
        $oSysTrNameData = TreeHomeworkList::getTrNameById(array_column($data['rows'],'iSysTrId'));
       // print_r($oSysTrNameData);
        //print_r($oSysTrNameData);exit;

        $iSysTrArr = array();
        if(count($data['rows'])){
            foreach ($data['rows'] as $key => $value) {
                $iSysTrArr[$value['iSysTrId']][] =  $value['iCreateUserId'];//先找题库，再找人
            }
        }
        //print_r($iSysTrArr);
        $teracherCourseWareData = array();
        if($iSysTrArr){
            foreach ($iSysTrArr as $key => $value){
                $teracherCourseWareList = array();
                $value && $teracherCourseWareList = $this->getDI()->get(self::OldService)->query("select count(li_id) as num,sum(li_times) as li_times,li_us_id from xh_product_exam{$key}.list_courseware where 1 and li_us_id in(".implode(',',$value).") group by li_us_id")->fetchAll();
                //echo "select count(li_id) as num,sum(li_times) as li_times,li_us_id from xh_product_exam{$key}.list_courseware where 1 and li_us_id in(".implode(',',$value).") group by li_us_id";
                if($teracherCourseWareList)foreach ($teracherCourseWareList as $k => $v){
                    $teracherCourseWareData[$key][$v['li_us_id']] = array('iESNum' => $v['num'],'sDuration'=> $v['li_times']);
                }

            }
        }
        //print_r($teracherCourseWareList);
        if(count($data['rows'])){
            foreach ($data['rows'] as $key => $value) {
                $data['rows'][$key]['sUserName'] = $oUserInfo[$value['iCreateUserId']];
                $data['rows'][$key]['iESNum'] = $teracherCourseWareData[$value['iSysTrId']][$value['iCreateUserId']]['iESNum'];
                $data['rows'][$key]['sDuration'] = ExplainStats::transform($teracherCourseWareData[$value['iSysTrId']][$value['iCreateUserId']]['sDuration']);
                $data['rows'][$key]['sSysTrName'] = $oSysTrNameData[$value['iSysTrId']]."({$value['iSysTrId']})";
                $data['rows'][$key]['iESNum'] =  $data['rows'][$key]['iESNum']? $data['rows'][$key]['iESNum']:0;
                $data['rows'][$key]['iKjlzSum'] =  $value['iKjlzSum']?$value['iKjlzSum']:0;
                $data['rows'][$key]['iKjlzDuration'] =  ExplainStats::transform($value['iKjlzDuration']?$value['iKjlzDuration']:0);
            }
        }
        $this->response->setJsonContent($data)->send();
    }

    /**
     * #方法说明：查看老师录制的题目
     * # Created by zsc
     */
    public function teacherTopicViewAction(){
        Assets::easyUI('js/statsexplain/teacherTopicView.js');
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain_List') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));
        $this->view->setVar('NavUl', '<ul class="breadcrumb"><li><i class="fa fa-home fa-lg"></i> 主页</li><li>统计查询</li><li>题库讲评</li><li>录制查看</li></ul>');
        $listButtonArr = array();
        //$listSearchArr[] = array('type'=>'select', 'id'=>'List_Search_Status', 'data'=>array('0'=>'按照老师姓名','1'=>'按照题库名称'));
       // $listSearchArr[] = ['type'=>'text', 'id'=>'list_search', 'name'=>'list_search', 'label'=>'搜索： '];
        $this->view->setVar('List', Template::createList('List', 'Explain_TeacherTopicView', [
        ]));
        $this->view->pick('statsexplain/teacherTopicView');
    }

    /**
     * #方法说明：查看老师录制的题目
     * # Created by zsc
     */
    public function getTeacherTopicViewAction(){
        Assets::easyUI('js/statsexplain/teacherTopicView.js');
        Main::showNavPosition();
        UserPower::checkUserPower('Stats_Explain_List') or die(Main::showMessageModal('对不起，您没有查看此页面的权限！', 109106001));
        $this->view->disable();
        $iSysTrId =  $this->request->get('iSysTrId');
        $iCreateUserId =  $this->request->get('iCreateUserId');
        $data = array();
        if(!$iSysTrId || !$iCreateUserId)return $this->response->setJsonContent($data)->send();
        $coursePlay = Main::getConfigByName(self::CoursePlay);
        $bind = array();
        $conditions = '1 AND iStatus = 1 ';
        if($iCreateUserId){
            $conditions .= ' AND iCreateUserId = {iCreateUserId}';
            $bind['iCreateUserId'] = $iCreateUserId;
        }
        if($iSysTrId){
            $conditions .= ' AND iSysTrId = {iSysTrId}';
            $bind['iSysTrId'] = $iSysTrId;
        }
        //$conditions.=' AND iSchoolId = 4160 ';
        $parameters = [
            'columns'    => [  'iSchoolId','iTrId','iSysHoId','iCreateUserId','iDuration','sContent','tCreateTime','tSyncTime'],
            'order'      => 'tSyncTime DESC',
            'conditions'    =>  $conditions,
            'bind'          => $bind
        ];
        $data = Main::runModelPaginator('\\Admin\\Models\\statsexplain\\ExplainStats', $parameters, true);
        if($this->request->get('dev')=='xh'){
            print_r($parameters);
            print_r($data);
        }
        if($data['rows'])foreach($data['rows'] as $key => $value){
            $iSysHoIdArr[] = $value['iSysHoId'];
        }
        $iSysHoIdArr && $homeworkArr = $this->getDI()->get(self::OldService)->query(
            "select a.ho_id,a.ho_zycontent,a.ho_ad_id,b.ad_id,b.ad_name from xh_product_exam{$iSysTrId}.homework_list_base as a LEFT JOIN xh_product_exam{$iSysTrId}.address_items_tree_user as b on(a.ho_ad_id=b.ad_id) where 1 and a.ho_id in(".implode(',',$iSysHoIdArr).") order by a.ho_id asc"
        )->fetchAll();
       if($homeworkArr)foreach ($homeworkArr as $key => $value){
           $homeworkData[$value['ho_id']] = $value;
       }
       $schoolInfoArr = $this->cacheSchoolInfo();
       if($data['rows'])foreach($data['rows'] as $key => $value){
            $data['rows'][$key]['coursewarePlayUrl'] = $coursePlay['url']."http://".$schoolInfoArr[$value['iSchoolId']]."/filebase/get_homeworkfile_nosqldb.php?fileid={$value['sContent']}&tr_id={$value['iTrId']}&co_id=0&li_id=0";
            $data['rows'][$key]['catalogName'] = $homeworkData[$value['iSysHoId']]['ad_name'];
            $data['rows'][$key]['stemContent'] = str_replace('../filebase/','http://data.yunzuoye.net/filebase/',$homeworkData[$value['iSysHoId']]['ho_zycontent']);
            $data['rows'][$key]['iDuration'] = ExplainStats::transform($value['iDuration']?$value['iDuration']:0);;
       }
        $this->response->setJsonContent($data)->send();
    }


    /**
     * #方法说明：学校详情
     * @return array
    # Created by zsc
     */
    public function cacheSchoolInfo($force=false){
        $cacheKey = 'old_center_school_info';
        $schooData = Cache::get($cacheKey);
        if(!$schooData || $force){
            $schooData = array();
            $schoolList = $this->getDI()->get(self::OldService)->query("select sy_id,sy_name ,sy_name3 from system_type where sy_type = 'szxx' and sy_name5 = 1")->fetchAll();
            if($schoolList)foreach ($schoolList as $key => $value){
                $sy_name_info = implode('|',$value['sy_name3']);
                $schooData[$value['sy_id']] = array(
                    'iSchoolId'   => $value['sy_id'],
                    'sDomain'     => $sy_name_info[2],
                    'sSchoolName' => $value['sy_name'],
                );
            }
            Cache::save($cacheKey, $schoolList);
        }
        return $schooData;
    }
}

